package com.wang.web3.data.service.impl;

import com.wang.web3.data.api.Api;
import com.wang.web3.data.service.ApiService;
import com.wang.web3.data.service.HttpDao;
import com.wang.web3.data.service.ICallBackListener;

import okhttp3.RequestBody;
import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by SAR on 2018/4/18.
 */

public class ApiServiceImpl implements ApiService {

    Api api = HttpDao.getInstance().getIServiceAPI();

    private static ApiServiceImpl apiService;

    public static ApiServiceImpl getInstence(){
        if (apiService == null){
            apiService = new ApiServiceImpl();
        }
        return  apiService;
    }

    @Override
    public Observable<String> apiConfig(String type) {
        Observable<String> observable =api.apiConfig();
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(new ICallBackListener() {
                    @Override
                    public void onSuccess(String mCallBackVo) {

                    }

                    @Override
                    public void onFaild(String mCallBackVo) {

                    }
                }));

        return null;
    }

    @Override
    public void userSave(RequestBody payload, ICallBackListener iCallBackListener) {

        api.userSave(payload).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(iCallBackListener));

    }

    @Override
    public void contractAddress(ICallBackListener iCallBackListener) {
        api.contractAddress().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(iCallBackListener));
    }

    @Override
    public void userInfo(String address, ICallBackListener iCallBackListener) {
        api.contractAddress().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(iCallBackListener));
    }

    @Override
    public void boxList(String address, ICallBackListener iCallBackListener) {
        api.boxList(address).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(iCallBackListener));
    }

    @Override
    public void keyList(String address, ICallBackListener iCallBackListener) {
        api.keyList(address).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(iCallBackListener));
    }

    @Override
    public void myGirlList(String address, ICallBackListener iCallBackListener) {
        api.myGirlList(address,"girl",1,20).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(iCallBackListener));
    }

    @Override
    public void myPropsList(String address, ICallBackListener iCallBackListener) {
        api.myPropsList(address,"props",1,20).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(iCallBackListener));
    }

    @Override
    public void transactionList(String address, ICallBackListener iCallBackListener) {
        api.transactionList(address,1,20).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(HttpDao.getInstance().createSubscriber(iCallBackListener));
    }

}
